// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import VueCookies from 'vue-cookies'
import Cookies from 'js-cookie'
import Login from '@/pages/login/Login'
import Head from '@/pages/Head'
import Body from '@/pages/Body'
import Paging from'@/components/Paging'
import Popup from '@/components/Popup'
import Table from '@/components/Table'
import ListTbale from '@/components/ListTbale'
import { MessageBox,Notification } from 'element-ui';
import axios from 'axios'

import qs from 'qs'
Vue.prototype.$axios = axios //全局注册，使用方法为:this.$axios
Vue.prototype.qs = qs
/*礼物*/
import Gclass from '@/pages/gift/Gclass'
/*游戏*/
import Packet from '@/pages/game/Packet'
Vue.use(VueCookies)
Vue.$cookies.config('1d')
Vue.use(ElementUI);
Vue.config.productionTip = false;
Vue.component('Popup',Popup)
Vue.component("Login",Login);
Vue.component('Head',Head);
Vue.component('Body',Body);
Vue.component('paging',Paging);
Vue.component('Table',Table);
Vue.component('ListTbale',ListTbale)
//路由锁
router.beforeEach((to, from, next) => {
    if (to.meta.requireAuth) {
        if (VueCookies.get('token')) {
			if(VueCookies.get('adminType')==to.meta.jurisdiction||VueCookies.get('adminType')<to.meta.jurisdiction){
        if(to.name=="Head"){
          next({name:'Body'})
        }else{
          	next()
        }

			}else{
       Notification.error({
                 title: '错误',
                 message: '暂无权限进入'
               });
			}

        }
        else {
         MessageBox.confirm(
                '尚未登录,请登录',
                '系统提示',
                {
                  confirmButtonText: '重新登录',
                  cancelButtonText: '取消',
                  type: 'warning'
                }
              ).then(() => {
              next({
                   path: '/Login',
                  })
              })

        }
    }
    else {
        next();
    }
})

/**
 * *********************************
 * 封装全局提示
 * */
Vue.prototype.$notifyMsg = function (title,msg,type) {
  this.$notify({
    title: title,
    message: msg,
    type: type || 'success'
  });
}
/**
 * *********************************
 * 封装全局确认框提示
 * */
Vue.prototype.$confirmMsg = function (msg,title,type,success,failure,successtext,failuretext) {
  if(!!msg){
    title = title || '提示'
    this.$confirm(msg, title, {
      confirmButtonText: successtext || '确定',
      cancelButtonText: failuretext || '取消',
      type: type || 'warning'
    }).then(() => {
      if(success){success()}
    }).catch(() => {
      if(failure){failure()}
    });
  }
}

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
